package com.guigu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.ShopInfo;
import com.guigu.service.ShopInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/shop/")
public class ShopInfoController {

    @Autowired
    ShopInfoService shopService;

    //添加商品
    @PostMapping("shop.action")
    public Map addShop(ShopInfo shop,
                       MultipartFile[] imgs,
                       HttpServletRequest request){
        return  shopService.addShop(shop,imgs,request);
    }

    //分页及所有
    @GetMapping("shop.action")
    public Page<ShopInfo> queryAllShops( ShopInfo shop,
                                        @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                        @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
        return shopService.queryAllShops(shop,pageno,pagesize);
    }

    //修改商品上架下架
    @PutMapping("shop.action")
    public Map isUp(@RequestBody ShopInfo shop){
        return shopService.isUp(shop);
    }

    //修改商品信息
    @PostMapping("editShop.action")
    public Map editShopById(ShopInfo shop,
                            MultipartFile[] files,
                            String[] filenames,
                            HttpServletRequest request){
        return shopService.editShopById(shop,files,filenames,request);
    }

    //id查询商品
    @GetMapping("queryShopById.action/{id}")
    public ShopInfo queryShopById(@PathVariable Integer id){
        return shopService.queryShopById(id);
    }

    //删除商品
    @DeleteMapping("deleteShopById.action")
    public Map deleteShopById(ShopInfo shop){
        return  shopService.deleteShopById(shop);
    }

}
